package alit.generator.bl.populator;

import alit.generator.bl.generator.Context;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;

/**
 * User: Alexander Litvinenko
 * Date: 11/19/11
 * Time: 2:02 PM
 */
public class DatetimePopulatorKit extends PopulatorKit {

    public static final String TYPE = "datetime";

    public static class FromAllRangePopulator implements IPopulator {

        private DateFormat formatter = new SimpleDateFormat("YYY-MM-dd HH:mm:ss");

        public static String getId() {
            return "fromAllRange";
        }

        public String populate(Context context) {
            Random random = new Random();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date(Math.abs(random.nextLong())));
            int min = 1970;
            int max = 5000;
            calendar.set(Calendar.YEAR, min + (int) (Math.random() * ((max - min) + 1)));
            return "'" + formatter.format(calendar.getTime()) + "'";
        }
    }

    @Override
    public String getSqlDialect() {
        return DialectUtils.MS_SQL_SERVER;
    }

    @Override
    public String getTypeName() {
        return TYPE;
    }

}